home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.uv.es
/
2014.11.ftp.uv.es.tar
/
ftp.uv.es
/
pub
/
mirror
/
MailDrop
/
plug-ins
/
SamplePlugInProjects.hqx
/
Sample Plug-in Projects
/
Mail Drop PlugIns.h
next >
Wrap
C/C++ Source or Header
|
1997-01-08
|
15KB
|
379 lines
/*
Project: Mail Drop
Name: Mail Drop PlugIns.h
Programmer: Carl Bell
Modified: 7-Jan-97
Documentation for writing plug-ins for Mail Drop doesn't exist, because this is still
being worked on. Here's an explanation of how things work currently.
Send any questions/comments/complaints to Carl_Bell@baylor.edu.
Mail Drop supports 68K and PPC code resource based plug-ins. Eventually, "fat" resources
and shared libraries will also be supported. For now, plug-ins are "one way", i.e., they
respond to commands from Mail Drop. Eventually, there will be some sort of callback
mechanism so plug-ins can get Mail Drop to do things for them.
At startup (and possibly when opening a prefs file, I can't remember right now) MD searches
for plug-ins in 4 different folders:
1) a folder in the same folder as Mail Drop called 'Plug-ins'
2) a folder in the same folder as Mail Drop called 'Mail Drop Plug-ins'
3) a folder inside the Extensions folder called 'Mail Drop Plug-ins'
4) a folder inside the System folder called 'Mail Drop Plug-ins'.
These folders will be searched recursively, so plug-ins can be located within folders
inside the plug-in folder(s). Mail Drop looks for files of types 'MDPL' (code resource
plug-ins) and 'shlb' (shared libraries) and creator 'MDrp' (MD's sig). You won't be able
to use your own BNDL resource if you want a different icon; use a custom icon instead.
Currently, shared libraries ('shlb') are ignored.
Mail Drop searches each 'MDPL' file for a resource of type 'M68K', 'MPPC', and 'MFAT', for
68K, native PPC, and fat resources respectively. It searches in order, so if you have both
a 68K and PPC resource, the PPC resource will be ignored. Native PPC plug-ins are ignored
on 68K Macs, but they will be used if you are running the 68K version of Mail Drop on a
PowerMac. Fat resources are currently ignored. If you have multiple resources of a particular
type, the file itself is ignored. In other words, each plug-in file should have one and only
one code resource in it. If you want both a 68K and native version of a plug-in, use fat
(not!) or use two different plug-in files.
Every plug-in must have a "description" resource ('MDPD' ID=128). This resource specifies
the plug-in's type (e.g., an address book import plug-in), some flags, the plug-in's name,
and its "about" string. The plug-in type is one of the 4 byte OSTypes defined below. Flags
are currently ignored. The name is a pascal string that is displayed to the user in popup
menus, etc. It is not necessarily the same as the plug-in's file's name. The about string
is a pascal string displayed in an "about" box.
A plug-in's entry point is defined as:
pascal OSErr main(short selector, MailDropPlugInPBPtr plugInPBPtr, void *plugInData);
selector tells the plug-in what Mail Drop wants it to do
plugInPBPtr is a pointer to a MailDropPlugInPB paramater block, explained below
plugInData is a pointer to data "owned" by the plug-in for use as "globals" (not
implemented yet, so ignore it)
The parameter block is a struct containing:
OSType type - the type of plugin that Mail Drop thinks it is calling
FSSpec spec - a FSSpec of the plug-in's file
other stuff, depending on the type of plug-in. See below.
Whenever a plug-in is called, it should first check for a nil paramater block and
an incorrect plug-in type, and return errNullParamBlock or errWrongPlugInType if
necessary. Both of these errors would indicate bugs in Mail Drop so they should
never occur (yeah, right) but it's better to be safe than sorry.
A plug-in is first called by Mail Drop with the selector selectorPrepare. This is where
the plug-in should do any initialization, set up "globals", etc. For now, ignore it and
return noErr. When Mail Drop is done with the plug-in, it calls it with the selector
selectorFinish. The plug-in should clean up after itself, release the "globals", etc.
If a plug-in is called with an invalid selector, e.g., a "Default Info" plug-in getting
an "Address Book Import" plug-in's selectorImportSetTypeCreator selector, it should return
errInvalidSelector. (This would be another bug in Mail Drop...) If some other error
occurs, e.g., memFullErr, the plug-in should return that error.
******************************************************************************************
- "Default Info" plug-ins -
These plug-ins are used by Mail Drop to set the default user, password, and imap server at
startup. Although you can (and should) specify the default IMAP server in Mail Drop's internal
preference resource, this won't work if your site has multiple IMAP servers. Note that it isn't
necessary to set all three of these items. The username and password are really not that much of
a problem because MD will bring up the login dialog if they aren't available. Setting the imap
server requires the user to go into the preferences dialog, which can be a hassle after a while.
This type of plug-in is different that all others because Mail Drop will use the first DefaultInfo
plug-in that it finds when searching the folders listed above.
Plug-in type:
plugInTypeDefaultInfo = 'Dflt'
Selectors:
selectorDefaultGetInfo = 100
Extra PB stuff:
char Username[80]; // These array sizes are not arbitrary but are the current internal
char Password[80]; // sizes used in Mail Drop. The strings are null terminated C strings
char IMAPServer[256]; // not pascal strings. Subject to change without notice. :-)
When MD needs the default info, it will call the plug-in with the selector selectorDefaultGetInfo.
The plug-in should get the information by some method and fill in the character arrays in the
parameter block. If the information isn't available, e.g., you don't know the user's password,
leave the array as is because it has already been "zeroed out".
******************************************************************************************
- "Address Book Import" plug-ins -
These plug-ins are used by Mail Drop to import addresses into Mail Drop's address book.
Note that this may very well change in the future as the address book's functionality
is enhanced, e.g., to allow nicknames, aliases, notes, etc., so any plug-in written may
have to be rewritten. Hopefully things will be backwards compatible.
Plug-in type:
plugInAddressImport = 'Impt'
Selectors:
selectorImportSetTypeCreator = 200,
selectorImportFile = 201
Extra PB stuff:
OSType fileType; // The type of file that we can import
OSType fileCreator; // The creator of file that we can import
FSSpec importFile; // The file that we want to import
Handle addresses; // The addresses
When the user selects the "Import" menu, MD bring up a standard file open dialog with a
pop-up menu that has a list of these plug-ins. MD will call the plug-in with the selector
selectorImportSetTypeCreator. If the plug-in only handles a certain type of file it should
set one or both of the PB's fileType and fileCreator fields. Mail Drop will only show files
of this type and/or creator in the standard file open dialog's list. These fields will
initially contain '****' which means all files/creators. If the plug-in doesn't deal with
specify file types, or files of a particular type but not a creator (e.g., 'TEXT') then
it should leave one or both these fields as is. Note that you specifying a fileType as
'****' and a particular creator will not show all files with that creator as you would
expect, but would instead show all files, i.e., the creator is ignored. This may change
in the future.
When the user has chosen the file to import, Mail Drop will call the plug-in with the
selector selectorImportFile. The file's FSSpec will be stored in the importFile field.
The plug-in should open the file, convert the file's contents into a specific format (as
detailed below) stored in a handle (the PB's addresses field), and return. It is the
plug-in's responsibility to create the addresses handle because it will be nil upon
entry. It is also the plug-in's responsibility to dispose the handle when it receives
the selectorFinish selector.
The converted addresses that are returned are a handle to a block of text that looks
like the following:
"personal name" <address>
"personal name" <address>
<address>
"personal name" <address>
"group name" <GROUP@GROUP>
"personal name" <address>
<address>
"personal name" <address>
etc.
The personal name, if there is one, needs to be in quotes even if there are no special
characters, e.g., periods. Each line should end with a CR, not LF or CRLF. There
should be a CR at the end of the last address, as well.
Addresses will be added to the main address book until a "group" line, i.e., one that has
the GROUP@GROUP address, is reached. A group called "group name" will be created, if it
doesn't already exist, and any address following that will be added to that group until
the next group line is reached.
The following functions can/should be used to "fix" address and name strings before they
are added to the text block. The characters below that return false are not permitted
by Mail Drop and the address will either be ignore by the import function, or the
invalid characters will be dropped.
Boolean ValidAddressChar(char ch)
{
if (ch < 32) return false;
if (ch == '<') return false;
if (ch == '>') return false;
if (ch == '\"') return false;
if (ch == '\\') return false;
if (ch == '\'') return false;
if (ch == ',') return false;
if (ch >= 127) return false;
return true;
}
Boolean ValidRealNameChar(char ch)
{
if (ch < 32) return false;
if (ch == '<') return false;
if (ch == '>') return false;
if (ch == '\\') return false;
if (ch == '(') return false;
if (ch == ')') return false;
if (ch == '@') return false;
if (ch >= 127) return false; // eventually 8 bit will work but not yet
return true;
}
******************************************************************************************
That's all folks....
*/
#pragma once
#ifndef __MAILDROPPLUGINS__
#define __MAILDROPPLUGINS__
#define kPlugInCreator 'MDrp' // file createor of plugin files (Mail Drop's sig)
#define kPlugInTypeResource 'MDPL' // file type of plugin resource file
#define kPlugInTypeSharedLib 'shlb' // file type of plugin shared library file
#define kPlugIn68KResType 'M68K' // resource type of 68K plugin
#define kPlugInPPCResType 'MPPC' // resource type of native PPC plugin
#define kPlugInFatResType 'MFAT' // resource type of "fat" plugin
#define kPlugInDescResType 'MDPD' // resource type of plugin description
#define kPlugInResourceID 128 // code resource plugins and description resources
// always use res id 128
// These are the possible types of plugins. The type field in a plugin's MailDropPlugInDesc
// resource must be one of these.
enum {
plugInTypeDefaultInfo = 'Dflt', // Used to set default user, password, and imap server at startup
plugInAddressImport = 'Impt', // Import addresses into address book
// These aren't supported yet...
plugInAuthentication = 'Auth', // Other IMAP authentication, e.g., kerberos
plugInAddressExport = 'Expt', // Export addresses from address book
plugInAddressSearch = 'Srch', // Search for an address, e.g., ph
plugInPreferences = 'Pref' // Alternate prefs file method, e.g., ACAP, Internet Config
};
// Flags - currently ignored :-/
#define plugInFlagUsesFile 0x00000001 // Needs access to its resources
#define plugInFlagKeepInMemory 0x00000002 // Keep in memory between calls if possible (i.e., may be called often)
// Mail Drop plugin Description 'MDPD' resource.
// I think this Rez type declaration is right, but haven't checked it. There should
// should be a ResEdit 'TMPL' inside Mail Drop in any case...
/*
type 'MDPD' { // Mail Drop Plugin Description resource
literal longint; // type
unsigned hex longint; // flags
pstring; // name
pstring; // about string
};
*/
// Mail Drop Plugin Parameter blocks and related oddities
// #define MailDropParamBlockHeader \
struct MailDropDefaultParam {
OSType type; // The type of plugin that Mail Drop thinks it is calling
FSSpec spec; // The plugin's home file
char Username[80]; // These array sizes are not arbitrary but are the current internal
char Password[80]; // sizes used in Mail Drop. The strings are null terminated C strings
char IMAPServer[256]; // not pascal strings. Subject to change without notice. :-)
};
typedef struct MailDropDefaultParam MailDropDefaultParam, *MailDropDefaultParamPtr;
struct MailDropImportParam {
OSType type; // The type of plugin that Mail Drop thinks it is calling
FSSpec spec; // The plugin's home file
OSType fileType; // The type of file that we can import
OSType fileCreator; // The creator of file that we can import
FSSpec importFile; // The file that we want to import
Handle addresses; // The addresses
};
typedef struct MailDropImportParam MailDropImportParam, *MailDropImportParamPtr;
struct MailDropCrapolaParam {
OSType type; // The type of plugin that Mail Drop thinks it is calling
FSSpec spec; // The plugin's home file
char crapola[80];
};
typedef struct MailDropCrapolaParam MailDropCrapolaParam, *MailDropCrapolaParamPtr;
union MailDropPlugInPB {
MailDropDefaultParam defaultParam;
MailDropImportParam importParam;
MailDropCrapolaParam crapolaParam;
};
typedef union MailDropPlugInPB MailDropPlugInPB, *MailDropPlugInPBPtr;
// Some error codes
enum {
errUnknownError = 1,
errNullParamBlock = 2,
errWrongPlugInType = 3,
errInvalidSelector = 4
};
// Selectors
enum {
selectorPrepare = 1,
selectorFinish = 2,
selectorDefaultGetInfo = 100,
selectorImportSetTypeCreator = 200,
selectorImportFile = 201
};
typedef pascal OSErr (*MailDropPlugInProc)(short selector, MailDropPlugInPBPtr plugInPBPtr, void *plugInData);
enum {
uppMailDropPlugInProcInfo = kPascalStackBased
| RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
| STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
| STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(MailDropPlugInPBPtr)))
| STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *)))
};
#if USESROUTINEDESCRIPTORS
typedef UniversalProcPtr MailDropPlugInUPP;
#define NewMailDropPlugInProc(userRoutine) \
(MailDropPlugInUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppMailDropPlugInProcInfo, GetCurrentArchitecture())
#define NewMailDropPlugInProc68K(userRoutine) \
(MailDropPlugInUPP)NewRoutineDescriptor((ProcPtr)(userRoutine), uppMailDropPlugInProcInfo, (ISAType)kM68kISA)
#define CallMailDropPlugInProc(userRoutine, selector, plugInPBPtr, plugInData) \
CallUniversalProc((UniversalProcPtr)(userRoutine), uppMailDropPlugInProcInfo, selector, plugInPBPtr, plugInData)
#else
typedef MailDropPlugInProc MailDropPlugInUPP;
#define NewMailDropPlugInProc(userRoutine) \
(MailDropPlugInUPP)(userRoutine)
#define NewMailDropPlugInProc68K(userRoutine) \
(MailDropPlugInUPP)(userRoutine)
#define CallMailDropPlugInProc(userRoutine, selector, plugInPBPtr, plugInData) \
(*(userRoutine))(selector, plugInPBPtr, plugInData)
#endif // USESROUTINEDESCRIPTORS
#endif // __MAILDROPPLUGINS__